﻿using Nancy;


namespace GeometryServer.Modules
{
    public class GeometryServerModule : NancyModule
    {
        public GeometryServerModule()
            : base("/rest/services/Geometry/GeometryServer/")
        {
            Get["/"] = parameters =>
            {
                string format = null;
                
                #region Optional Parameter
                if ((Request.Query["f"].Value != null))
                {
                    format = Request.Query["f"].Value;
                }
                else
                {
                    format = "HTML";
                }
                #endregion


                if (format.Equals("json"))
                {
                    var root = new GISServer.Core.Client.GeometryService.Root();
                    root.ServiceDescription = "This is geometry service";
                    //root.Operations = new System.Collections.Generic.List<string>();
                    //root.Operations.Add("Project");
                    //root.Operations.Add("Simplify");
                    //root.Operations.Add("Buffer");
                    //root.Operations.Add("Areas And Lengths");
                    //root.Operations.Add("Lengths");
                    //root.Operations.Add("Label Points");
                    //root.Operations.Add("Relation");
                    //root.Operations.Add("Densify");
                    //root.Operations.Add("Distance");
                    //root.Operations.Add("Union");
                    //root.Operations.Add("Intersect");
                    //root.Operations.Add("Difference");
                    //root.Operations.Add("Cut");
                    //root.Operations.Add("TrimExtend");
                    //root.Operations.Add("Offset");
                    //root.Operations.Add("Generalize");
                    //root.Operations.Add("AutoComplete");
                    //root.Operations.Add("Reshape");
                    //root.Operations.Add("ConvexHull");
                    var resultstring = Services.Utilities.getJSON(root);
                    return Services.Utilities.GetJsonResponseObject(resultstring);
                }
                else
                {
                        return View["GeometryService"];
                }

            };

        }
    }
}